package huawei.widget;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Typeface;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowInsets;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.FragmentActivity;
import o.fna;
import o.fo;
import o.fpy;
import o.fql.d;
import o.fql.g;
import o.fql.h;
import o.FragmentTransaction;

public class HwSubTabWidget extends LinearLayout {
    private static final int DEFAULT_BLUR_TYPE = 4;
    private static final int DICHOTOMY_SIZE = 2;
    private static final int INVALID_BLUR_OVERLAY_COLOR = -16777216;
    private static final String TAG = "HwSubTabWidget";
    private fpy mBlurEngine;
    private int mBlurOverlayColor;
    private int mBlurTypeValue;
    private Context mContext;
    private ImageView mFunctionView;
    private boolean mIsBlurEnable;
    private boolean mIsClickable;
    private boolean mIsConfigChange;
    private boolean mIsSetSubTab;
    private int mLastPos;
    private int mLastSubTab;
    private Typeface mMedium;
    private Typeface mRegular;
    private fna mSafeInsets;
    private a mSelectedSubTab;
    private e mSubTabClickListener;
    private HwSubTabViewContainer mSubTabContainer;
    private huawei.widget.HwSubTabViewContainer.a mSubTabContentView;
    private int mSubTabItemBg;
    private int mSubTabItemMargin;
    private int mSubTabItemMinWidth;
    private int mSubTabItemPadding;
    private ColorStateList mSubTabItemTextColors;
    private int mSubTabItemTextSize;

    static class SavedState extends BaseSavedState {
        public static final Creator<SavedState> CREATOR = new Creator<SavedState>() {
            public /* synthetic */ Object createFromParcel(Parcel parcel) {
                return ˋ(parcel);
            }

            public /* synthetic */ Object[] newArray(int i) {
                return ˏ(i);
            }

            public SavedState ˋ(Parcel parcel) {
                return new SavedState(parcel);
            }

            public SavedState[] ˏ(int i) {
                return new SavedState[i];
            }
        };
        private int ˏ;

        SavedState(Parcelable parcelable) {
            super(parcelable);
        }

        SavedState(Parcel parcel) {
            super(parcel);
            this.ˏ = parcel.readInt();
        }

        public void writeToParcel(Parcel parcel, int i) {
            super.writeToParcel(parcel, i);
            parcel.writeInt(this.ˏ);
        }
    }

    public class a {
        private Object ˊ;
        final /* synthetic */ HwSubTabWidget ˋ;
        private b ˎ;
        private int ˏ;
        private CharSequence ॱ;
        private int ॱॱ;

        public a(HwSubTabWidget hwSubTabWidget, CharSequence charSequence, b bVar) {
            this(hwSubTabWidget, charSequence, bVar, null);
        }

        public a(HwSubTabWidget hwSubTabWidget, CharSequence charSequence, b bVar, Object obj) {
            this.ˋ = hwSubTabWidget;
            this.ˏ = -1;
            this.ॱॱ = -1;
            this.ॱ = charSequence;
            this.ˎ = bVar;
            this.ˊ = obj;
        }

        public b ॱ() {
            return this.ˎ;
        }

        public int ˏ() {
            return this.ˏ;
        }

        public CharSequence ˎ() {
            return this.ॱ;
        }

        public void ˊ() {
            this.ˋ.ˏ(this);
        }

        public void ˎ(int i) {
            this.ˏ = i;
        }

        public a ॱ(CharSequence charSequence) {
            this.ॱ = charSequence;
            if (this.ˏ >= 0) {
                this.ˋ.ˊ(this.ˏ);
            }
            return this;
        }

        public int ˋ() {
            return this.ॱॱ;
        }
    }

    public interface b {
        void ˊ(a aVar, FragmentTransaction kaVar);

        void ˎ(a aVar, FragmentTransaction kaVar);

        void ॱ(a aVar, FragmentTransaction kaVar);
    }

    class c extends TextView {
        final /* synthetic */ HwSubTabWidget ˋ;
        private a ˎ;

        c(HwSubTabWidget hwSubTabWidget, Context context, a aVar) {
            this.ˋ = hwSubTabWidget;
            super(context, null, 0);
            this.ˎ = aVar;
            setGravity(17);
            setMaxLines(1);
            setPadding(hwSubTabWidget.mSubTabItemPadding, 0, hwSubTabWidget.mSubTabItemPadding, 0);
            setTextSize(0, (float) hwSubTabWidget.mSubTabItemTextSize);
            setTextColor(hwSubTabWidget.mSubTabItemTextColors);
            setBackgroundResource(hwSubTabWidget.mSubTabItemBg);
            setMinWidth(hwSubTabWidget.mSubTabItemMinWidth);
            ˏ();
        }

        public a ॱ() {
            return this.ˎ;
        }

        public void ˏ() {
            CharSequence ˎ = this.ˎ.ˎ();
            if ((!TextUtils.isEmpty(ˎ) ? 1 : 0) != 0) {
                setText(ˎ);
                setVisibility(0);
            } else {
                setVisibility(8);
                setText(null);
            }
            if (this.ˎ.ˋ() != -1) {
                setId(this.ˎ.ˋ());
            }
        }
    }

    class e implements OnClickListener {
        final /* synthetic */ HwSubTabWidget ˏ;

        private e(HwSubTabWidget hwSubTabWidget) {
            this.ˏ = hwSubTabWidget;
        }

        public void onClick(View view) {
            if (this.ˏ.mIsClickable) {
                int childCount = this.ˏ.mSubTabContentView.getChildCount();
                for (int i = 0; i < childCount; i++) {
                    boolean z;
                    View childAt = this.ˏ.mSubTabContentView.getChildAt(i);
                    if (childAt == view) {
                        z = true;
                    } else {
                        z = false;
                    }
                    childAt.setSelected(z);
                    if (childAt == view) {
                        this.ˏ.mLastPos;
                        if (this.ˏ.mIsSetSubTab && this.ˏ.mLastSubTab != -1) {
                            this.ˏ.mLastSubTab;
                        }
                        this.ˏ.mIsSetSubTab = false;
                        this.ˏ.mLastPos = i;
                        this.ˏ.mSubTabContainer.ˏ(i);
                    }
                }
                if (view instanceof c) {
                    ((c) view).ॱ().ˊ();
                }
            }
        }
    }

    public HwSubTabWidget(Context context) {
        this(context, null);
    }

    public HwSubTabWidget(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, o.fql.a.ˋ);
    }

    public HwSubTabWidget(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.mIsClickable = true;
        this.mBlurEngine = fpy.ॱ();
        this.mIsBlurEnable = false;
        this.mIsConfigChange = false;
        this.mBlurOverlayColor = INVALID_BLUR_OVERLAY_COLOR;
        this.mBlurTypeValue = 4;
        this.mIsSetSubTab = false;
        this.mLastSubTab = -1;
        this.mContext = context;
        this.mSafeInsets = new fna(this);
        View inflate = ((LayoutInflater) getContext().getSystemService("layout_inflater")).inflate(h.ॱ, this, true);
        this.mSubTabContainer = (HwSubTabViewContainer) inflate.findViewById(d.ˊ);
        this.mFunctionView = (ImageView) inflate.findViewById(d.ˎ);
        this.mSubTabContentView = this.mSubTabContainer.ˎ();
        setOrientation(0);
        this.mMedium = Typeface.create("HwChinese-medium", 0);
        this.mRegular = Typeface.create("sans-serif", 0);
        this.mSubTabContentView.ˏ(getResources().getDimensionPixelSize(o.fql.c.ˊ));
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, g.ˊˋ, i, i.ˋ);
        this.mSubTabContentView.ˊ(obtainStyledAttributes.getDimensionPixelOffset(g.ˋˊ, getResources().getDimensionPixelOffset(o.fql.c.ˎ)));
        this.mSubTabContentView.ॱ(obtainStyledAttributes.getDimensionPixelOffset(g.ˍ, 0));
        this.mSubTabContentView.setSelectedIndicatorColor(obtainStyledAttributes.getColor(g.ˊˊ, fo.ˋ(context, o.fql.b.ˏ)));
        this.mSubTabItemPadding = obtainStyledAttributes.getDimensionPixelOffset(g.ˉ, getResources().getDimensionPixelOffset(o.fql.c.ˋ));
        this.mSubTabItemMargin = obtainStyledAttributes.getDimensionPixelOffset(g.ˎˎ, getResources().getDimensionPixelOffset(o.fql.c.ॱ));
        this.mSubTabContainer.ˋ(this.mSubTabItemMargin);
        this.mSubTabItemBg = obtainStyledAttributes.getResourceId(g.ˋˋ, o.fql.e.ˏ);
        this.mSubTabItemMinWidth = obtainStyledAttributes.getDimensionPixelOffset(g.ˌ, 0);
        this.mSubTabItemTextSize = obtainStyledAttributes.getDimensionPixelSize(g.ˋᐝ, getResources().getDimensionPixelSize(o.fql.c.ᐝ));
        this.mSubTabItemTextColors = obtainStyledAttributes.getColorStateList(g.ˑ);
        this.mBlurTypeValue = obtainStyledAttributes.getInteger(g.ˏˏ, 4);
        this.mBlurOverlayColor = obtainStyledAttributes.getColor(g.ˏˎ, INVALID_BLUR_OVERLAY_COLOR);
        obtainStyledAttributes.recycle();
    }

    public void ॱ(a aVar, boolean z) {
        View ˊ = ˊ(aVar);
        LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -1);
        ˊ.setLayoutParams(layoutParams);
        layoutParams.setMarginStart(this.mSubTabItemMargin);
        layoutParams.setMarginEnd(this.mSubTabItemMargin);
        this.mSubTabContentView.addView(ˊ, layoutParams);
        aVar.ˎ(ॱ() - 1);
        if (z) {
            aVar.ˊ();
            ˊ.setSelected(true);
        }
    }

    public Parcelable onSaveInstanceState() {
        if (this.mContext.getApplicationInfo().targetSdkVersion <= 18) {
            return super.onSaveInstanceState();
        }
        int ˊ = ˊ();
        Parcelable savedState = new SavedState(super.onSaveInstanceState());
        savedState.ˏ = ˊ;
        return savedState;
    }

    public void onRestoreInstanceState(Parcelable parcelable) {
        if (this.mContext.getApplicationInfo().targetSdkVersion <= 18) {
            super.onRestoreInstanceState(parcelable);
        } else if (parcelable instanceof SavedState) {
            SavedState savedState = (SavedState) parcelable;
            super.onRestoreInstanceState(savedState.getSuperState());
            int ॱ = savedState.ˏ;
            if (ॱ >= 0 && ॱ < ॱ()) {
                ˎ(ॱ).ˊ();
                ((c) this.mSubTabContentView.getChildAt(ॱ)).setSelected(true);
                this.mLastPos = ॱ;
            }
        } else {
            super.onRestoreInstanceState(parcelable);
        }
    }

    public void setClickable(boolean z) {
        this.mIsClickable = z;
    }

    public int ˊ() {
        int ॱ = ॱ();
        for (int i = 0; i < ॱ; i++) {
            if (this.mSelectedSubTab == ˎ(i)) {
                return i;
            }
        }
        return -1;
    }

    public void setSubTabSelected(int i) {
        a ˎ = ˎ(i);
        if (!((this.mSelectedSubTab != null && this.mSelectedSubTab.ˏ() != -1) || ˎ == null || ˎ.ˏ() == -1)) {
            this.mSubTabContainer.setScrollPosition(ˎ.ˏ(), 0.0f);
        }
        this.mSelectedSubTab = ˎ;
        ॱ(i);
        if (this.mLastPos != i) {
            this.mLastSubTab = this.mLastPos;
            this.mIsSetSubTab = true;
        }
        this.mLastPos = i;
    }

    public void ˊ(int i, int i2, boolean z) {
        if (z) {
            for (int i3 = i + 1; i3 < i2; i3++) {
                a ˎ = ˎ(i3);
                if (ˎ != null) {
                    ˎ.ˎ(i3);
                }
            }
            return;
        }
        while (i < i2) {
            a ˎ2 = ˎ(i);
            if (ˎ2 != null) {
                ˎ2.ˎ(i);
            }
            i++;
        }
    }

    private void ॱ(int i) {
        int childCount = this.mSubTabContentView.getChildCount();
        for (int i2 = 0; i2 < childCount; i2++) {
            boolean z;
            TextView textView = (TextView) this.mSubTabContentView.getChildAt(i2);
            if (i2 == i) {
                z = true;
            } else {
                z = false;
            }
            if (i2 == i) {
                textView.setTypeface(this.mMedium);
            } else {
                textView.setTypeface(this.mRegular);
            }
            textView.setSelected(z);
        }
    }

    public a ˎ(int i) {
        View childAt = this.mSubTabContentView.getChildAt(i);
        return childAt != null ? ((c) childAt).ॱ() : null;
    }

    public int ॱ() {
        return this.mSubTabContentView.getChildCount();
    }

    public void ˋ(int i) {
        int i2 = 0;
        if (this.mSubTabContentView != null) {
            a ˎ = ˎ(i);
            if (ˎ != null) {
                ˎ.ˎ(-1);
            }
            this.mSubTabContentView.removeViewAt(i);
            if (ॱ() == 0) {
                this.mSelectedSubTab = null;
            }
            ˊ(i, ॱ(), false);
            if (ˎ == this.mSelectedSubTab) {
                if (i - 1 > 0) {
                    i2 = i - 1;
                }
                ˏ(ˎ(i2));
            }
        }
    }

    public void ˎ() {
        if (this.mSubTabContentView != null) {
            this.mSubTabContentView.removeAllViews();
            this.mSelectedSubTab = null;
        }
    }

    public void ˏ(a aVar) {
        int i = -1;
        FragmentTransaction kaVar = null;
        if (this.mContext instanceof FragmentActivity) {
            kaVar = ((FragmentActivity) this.mContext).ˏॱ().ˊ().ʻ();
        }
        if (!((this.mSelectedSubTab != null && this.mSelectedSubTab.ˏ() != -1) || aVar == null || aVar.ˏ() == -1)) {
            this.mSubTabContainer.setScrollPosition(aVar.ˏ(), 0.0f);
        }
        if (this.mSelectedSubTab != aVar) {
            if (aVar != null) {
                i = aVar.ˏ();
            }
            ॱ(i);
            if (this.mSelectedSubTab != null) {
                this.mSelectedSubTab.ॱ().ॱ(this.mSelectedSubTab, kaVar);
            }
            this.mSelectedSubTab = aVar;
            if (this.mSelectedSubTab != null) {
                this.mSelectedSubTab.ॱ().ˎ(this.mSelectedSubTab, kaVar);
            }
        } else if (this.mSelectedSubTab != null) {
            this.mSelectedSubTab.ॱ().ˊ(this.mSelectedSubTab, kaVar);
        }
        if (kaVar != null && !kaVar.ʽ()) {
            kaVar.ˏ();
        }
    }

    public void ˊ(int i) {
        c cVar = (c) this.mSubTabContentView.getChildAt(i);
        if (cVar != null) {
            cVar.ˏ();
        }
    }

    private c ˊ(a aVar) {
        c cVar = new c(this, getContext(), aVar);
        cVar.setFocusable(true);
        if (this.mSubTabClickListener == null) {
            this.mSubTabClickListener = new e();
        }
        cVar.setOnClickListener(this.mSubTabClickListener);
        return cVar;
    }

    public void setSubTabScrollingOffsets(int i, float f) {
        this.mSubTabContainer.setScrollPosition(i, f);
    }

    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        this.mSafeInsets.ˎ(getPaddingLeft(), getPaddingTop(), getPaddingRight(), getPaddingBottom());
    }

    public void setPadding(int i, int i2, int i3, int i4) {
        super.setPadding(i, i2, i3, i4);
        this.mSafeInsets.ˎ(i, i2, i3, i4);
    }

    public WindowInsets onApplyWindowInsets(WindowInsets windowInsets) {
        this.mSafeInsets.ॱ(windowInsets);
        return super.onApplyWindowInsets(windowInsets);
    }

    protected void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        this.mIsConfigChange = true;
    }

    public void onLayout(boolean z, int i, int i2, int i3, int i4) {
        super.onLayout(z, i, i2, i3, i4);
        if (this.mIsConfigChange) {
            if (!(this.mSelectedSubTab == null || this.mSelectedSubTab.ˏ() == -1)) {
                setSubTabScrollingOffsets(this.mSelectedSubTab.ˏ(), 0.0f);
            }
            this.mIsConfigChange = false;
        }
        this.mSafeInsets.ˊ(true);
    }

    protected void onMeasure(int i, int i2) {
        int i3;
        int childCount = this.mSubTabContentView.getChildCount();
        for (i3 = 0; i3 < childCount; i3++) {
            View childAt = this.mSubTabContentView.getChildAt(i3);
            ((LinearLayout.LayoutParams) childAt.getLayoutParams()).width = -2;
            childAt.setPadding(0, 0, 0, 0);
        }
        int childMeasureSpec = getChildMeasureSpec(i, getPaddingLeft() + getPaddingRight(), Integer.MIN_VALUE);
        this.mSubTabContentView.measure(childMeasureSpec, i2);
        this.mSubTabContainer.measure(childMeasureSpec, i2);
        childMeasureSpec = this.mSubTabContentView.getMeasuredWidth();
        super.onMeasure(i, i2);
        int measuredWidth = getMeasuredWidth() / 2;
        if (childMeasureSpec < measuredWidth && childCount > 0) {
            int i4 = (measuredWidth - ((childCount - 1) * (this.mSubTabItemMargin + this.mSubTabItemMargin))) / childCount;
            childMeasureSpec = 0;
            while (childMeasureSpec < childCount) {
                View childAt2 = this.mSubTabContentView.getChildAt(childMeasureSpec);
                if (childAt2 != null && childAt2.getMeasuredWidth() <= i4) {
                    childMeasureSpec++;
                } else {
                    return;
                }
            }
            for (i3 = 0; i3 < childCount; i3++) {
                View childAt3 = this.mSubTabContentView.getChildAt(i3);
                int measuredWidth2 = childAt3.getMeasuredWidth();
                if (measuredWidth2 < i4) {
                    measuredWidth2 = (i4 - measuredWidth2) / 2;
                    childAt3.setPadding(measuredWidth2, 0, measuredWidth2, 0);
                }
                LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) childAt3.getLayoutParams();
                if (i3 == childCount - 1) {
                    layoutParams.width = measuredWidth - ((childCount - 1) * ((this.mSubTabItemMargin + this.mSubTabItemMargin) + i4));
                } else {
                    layoutParams.width = i4;
                }
            }
            super.onMeasure(i, i2);
        }
    }

    public huawei.widget.HwSubTabViewContainer.a ˏ() {
        return this.mSubTabContentView;
    }

    public void draw(Canvas canvas) {
        if (this.mBlurEngine.ॱ(this)) {
            this.mBlurEngine.ˊ(canvas, (View) this);
            super.dispatchDraw(canvas);
            return;
        }
        super.draw(canvas);
    }

    protected void onWindowVisibilityChanged(int i) {
        super.onWindowVisibilityChanged(i);
        if (i == 0) {
            this.mBlurEngine.ˋ(this, this.mBlurEngine.ˋ(this.mBlurTypeValue));
            this.mBlurEngine.ˊ((View) this, ˋ());
            if (this.mBlurOverlayColor != INVALID_BLUR_OVERLAY_COLOR) {
                this.mBlurEngine.ˏ(this, this.mBlurOverlayColor);
                return;
            }
            return;
        }
        this.mBlurEngine.ˏ(this);
    }

    public boolean ˋ() {
        return this.mIsBlurEnable;
    }

    public void setBlurEnable(boolean z) {
        this.mIsBlurEnable = z;
        this.mBlurEngine.ˊ((View) this, ˋ());
    }

    public void setBlurColor(int i) {
        this.mBlurOverlayColor = i;
    }

    public void setBlurType(int i) {
        this.mBlurTypeValue = i;
    }
}
